<?php
/**
 * Created by PhpStorm.
 * User: 异步加载
 * Date: 2017/12/28
 * Time: 21:45
 */

namespace app\api\controller\v1;

use app\api\controller\BaseController;
use app\api\model\Advertising as AdAdvertisingModel;
use app\lib\validate\IDMustBePostiveInt;
use app\lib\exception\AdvertisingException;

class Advertising extends BaseController
{
    /**
     * @return \think\response\Json
     * @throws AdvertisingException
     * 获取所有广告items
     */
    public function getAllAd(){
        $aditems = AdAdvertisingModel::all();
        if(!$aditems){
            throw new AdvertisingException();
        }
        return json($aditems,200);
    }

    /**
     * @param $id
     * @return \think\response\Json
     * @throws AdvertisingException
     * 获取特定广告详情
     */
    public function getAdDetail($id){
        (new IDMustBePostiveInt())->gocheck();
        $detail = AdAdvertisingModel::getDetail($id);
        if(!$detail){
            throw new AdvertisingException();
        }
        return json($detail,200);
    }

}